From 1be701b0325bf7b01d52523004ea4555f25b83de Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Mon, 15 Aug 2005 14:42:07 +0000 Subject: [PATCH] BablFishReference is coming to life --- ChangeLog | 15 ++++++++ babl/babl-classes.h | 5 +-- babl/babl-fish.c | 47 +++++++++++++++++++++-- babl/babl-ids.h | 1 + babl/babl-image.c | 83 +++++++++++++++++++++++++++++++++++----- babl/babl-image.h | 7 ++++ babl/babl-type.c | 9 ++++- tests/grayscale_to_rgb.c | 3 +- 8 files changed, 150 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5e41083..bde9a00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2005-08-15 Øyvind Kolås + + * babl/babl-classes.h: BablPixelFormat: changed order of attributes to + match BablModel. BablFish: removed **from and **to lists, since they + were added at a wrong offset from the instance start anyways. + * babl/babl-fish.c: Made the reference fish work for linear buffers + with constant datatype + * babl/babl-ids.h: added BABL_RGBA_DOUBLE + * babl/babl-image.[ch]: made BablImage be allocated in a single chunk, + added babl_image_new_from_linear() + * babl/babl-type.c: added assertion about bits%8==0 + * babl/babl-base/babl-base-conversions-model.c: made BABL_PLANAR_SANITY accept + single band buffers. added conversions for premultiplied grayscale. + * babl/babl-base/babl-base-pixel-formats.c: added "rgba-double" + 2005-08-15 Øyvind Kolås * Makefile-mini: compile both the nop and introspect programs by diff --git a/babl/babl-classes.h b/babl/babl-classes.h index 4055fc9..a4f0786 100644 --- a/babl/babl-classes.h +++ b/babl/babl-classes.h @@ -169,8 +169,8 @@ typedef struct BablInstance instance; BablConversion **from; /*< NULL terminated list of conversions from class */ BablConversion **to; /*< NULL terminated list of conversions to class */ - int planar; int bands; + int planar; BablModel **model; BablComponent **component; BablType **type; @@ -197,9 +197,6 @@ typedef struct typedef struct { BablFish fish; - BablConversion **from; /*< these are here for a later stage, when calculated*/ - BablConversion **to; /*< reference conversions can be used for "segment" */ - /*< conversions where no other conversions exist. */ BablConversion *type_to_double; BablConversion *model_to_rgba; BablConversion *rgba_to_model; diff --git a/babl/babl-fish.c b/babl/babl-fish.c index 938e8c2..0e376af 100644 --- a/babl/babl-fish.c +++ b/babl/babl-fish.c @@ -25,6 +25,8 @@ #include "babl-type.h" #include "babl-model.h" +#include "babl-image.h" +#include "babl-pixel-format.h" static int each_babl_fish_destroy (Babl *babl, @@ -185,6 +187,8 @@ void *fooA; void *fooB; void *fooC; +#define BABL_MAX_BANDS 32 + int babl_fish_process (BablFish *babl_fish, void *source, @@ -192,10 +196,12 @@ babl_fish_process (BablFish *babl_fish, int n) { Babl *babl; + BablImage *imageA; + BablImage *imageB; + BablImage *imageC; - fooA = malloc(1000); - fooB = malloc(1000); - fooC = malloc(1000); + fooA = babl_malloc(sizeof (double) * n * 4); + fooB = babl_malloc(sizeof (double) * n * 4); assert (source); assert (destination); @@ -214,15 +220,50 @@ babl_fish_process (BablFish *babl_fish, fooA, n* ((BablPixelFormat*)(babl_fish->source))->bands ); + /* calculate planar representation of fooA, and fooB */ + + imageA = babl_image_new_from_linear (fooA, + (Babl*) ((BablPixelFormat*) babl->fish.source)->model[0]); + imageB = babl_image_new_from_linear (fooB, (Babl*)babl_model_id (BABL_RGBA)); /* transform fooA into fooB fooB is rgba double */ + + ((BablConversion*)(babl->reference_fish.model_to_rgba))->function.planar( + imageA->bands, + imageA->data, + imageA->pitch, + imageB->bands, + imageB->data, + imageB->pitch, + n); + babl_free (imageA); + babl_free (imageB); + /* calculate planar representation of fooC */ /* transform fooB into fooC fooC is ???? double */ + imageB = babl_image_new_from_linear (fooB, (Babl*)babl_model_id (BABL_RGBA)); + imageC = babl_image_new_from_linear (fooA, (Babl*)((BablPixelFormat*)babl->fish.destination)->model[0]); + + ((BablConversion*)(babl->reference_fish.rgba_to_model))->function.planar( + imageB->bands, + imageB->data, + imageB->pitch, + imageC->bands, + imageC->data, + imageC->pitch, + n); + + ((BablConversion*)(babl->reference_fish.double_to_type))->function.linear( fooA, destination, n * ((BablPixelFormat*)(babl_fish->destination))->bands ); + babl_free (imageB); + babl_free (imageC); + + babl_free (fooA); + babl_free (fooB); return 0; } diff --git a/babl/babl-ids.h b/babl/babl-ids.h index 2b284e3..84656b3 100644 --- a/babl/babl-ids.h +++ b/babl/babl-ids.h @@ -78,6 +78,7 @@ enum { BABL_SRGBA, BABL_RGB_FLOAT, BABL_RGBA_FLOAT, + BABL_RGBA_DOUBLE, BABL_CMYK_FLOAT, BABL_CMYKA_FLOAT, BABL_YUV420, diff --git a/babl/babl-image.c b/babl/babl-image.c index 6f398c7..48f470d 100644 --- a/babl/babl-image.c +++ b/babl/babl-image.c @@ -34,9 +34,6 @@ static int each_babl_image_destroy (Babl *babl, void *data) { - babl_free (babl->image.component); - babl_free (babl->image.pitch); - babl_free (babl->image.stride); babl_free (babl); return 0; /* continue iterating */ @@ -53,7 +50,18 @@ image_new (int bands, Babl *self; int band; - self = babl_calloc (sizeof (BablImage), 1); + self = babl_calloc ( + sizeof (BablImage) + + sizeof (BablComponent*) * (bands+1) + + sizeof (void*) * (bands+1) + + sizeof (int) * (bands+1) + + sizeof (int) * (bands+1),1); + + self->image.component = ((void *)self) + sizeof (BablImage); + self->image.data = ((void *)self->image.component) + sizeof (BablComponent*) * (bands+1); + self->image.pitch = ((void *)self->image.data) + sizeof (void*) * (bands+1); + self->image.stride = ((void *)self->image.pitch) + sizeof (int) * (bands+1); +/*self->image.foo = ((void *)self->image.stride) + sizeof (int) * (bands+1);*/ self->class_type = BABL_IMAGE; self->instance.id = 0; @@ -61,11 +69,6 @@ image_new (int bands, self->image.bands = bands; - self->image.component = babl_malloc (sizeof (BablComponent*) * (bands+1)); - self->image.data = babl_malloc (sizeof (void*) * (bands+1)); - self->image.pitch = babl_malloc (sizeof (int) * (bands+1)); - self->image.stride = babl_malloc (sizeof (int) * (bands+1)); - for (band=0; band < bands; band++) { self->image.component[band] = component[band]; @@ -81,6 +84,66 @@ image_new (int bands, return (BablImage*) self; } +BablImage * +babl_image_new_from_linear (void *buffer, + Babl *babl) +{ + BablImage *self; + int band; + BablComponent *component [BABL_MAX_BANDS]; + void *data [BABL_MAX_BANDS]; + int pitch [BABL_MAX_BANDS]; + int stride [BABL_MAX_BANDS]; + + int offset=0; + int calc_pitch=0; + + switch (babl->class_type) + { + case BABL_PIXEL_FORMAT: + for (band=0; band < babl->pixel_format.bands; band++) + { + BablType *type = babl->pixel_format.type[band]; + calc_pitch += (type->bits / 8); + } + + for (band=0; band < babl->pixel_format.bands; band++) + { + BablType *type = babl->pixel_format.type[band]; + + component[band] = babl->pixel_format.component[band]; + data[band] = buffer + offset; + pitch[band] = calc_pitch; + stride[band] = 0; + + offset += (type->bits / 8); + } + break; + case BABL_MODEL: + for (band=0; band < babl->model.components; band++) + { + calc_pitch += (64 / 8); + } + + for (band=0; band < babl->model.components; band++) + { + component[band] = babl->model.component[band]; + data[band] = buffer + offset; + pitch[band] = calc_pitch; + stride[band] = 0; + + offset += (64 / 8); + } + break; + default: + babl_log ("%s(): Eeek!", __FUNCTION__); + break; + } + + self = image_new (babl->model.components, component, data, pitch, stride); + return self; +} + BablImage * babl_image_new (void *first, ...) @@ -148,7 +211,7 @@ babl_image_new (void *first, void babl_image_each (BablEachFunction each_fun, - void *user_data) + void *user_data) { int i; return; diff --git a/babl/babl-image.h b/babl/babl-image.h index db4a0c5..50b351c 100644 --- a/babl/babl-image.h +++ b/babl/babl-image.h @@ -29,4 +29,11 @@ void babl_image_each (BablEachFunction each_fun, void babl_image_destroy (void); BablImage * babl_image_new (void *first_component, ...); + +/* create a new BablImage based on a packed BablPixelFormat (or BablModel assumed to + * use only doubles). + */ +BablImage * +babl_image_new_from_linear (void *buffer, + Babl *format); #endif diff --git a/babl/babl-type.c b/babl/babl-type.c index 211733d..4db95bd 100644 --- a/babl/babl-type.c +++ b/babl/babl-type.c @@ -17,11 +17,13 @@ * Boston, MA 02111-1307, USA. */ +#include +#include +#include + #include "babl-internal.h" #include "babl-db.h" -#include -#include static int each_babl_type_destroy (Babl *babl, @@ -42,6 +44,9 @@ type_new (const char *name, { Babl *self; + assert (bits != 0); + assert (bits % 8 == 0); + self = babl_calloc (sizeof (BablType), 1); self->class_type = BABL_TYPE; self->instance.id = id; diff --git a/tests/grayscale_to_rgb.c b/tests/grayscale_to_rgb.c index 7d3e717..deb9cac 100644 --- a/tests/grayscale_to_rgb.c +++ b/tests/grayscale_to_rgb.c @@ -53,7 +53,8 @@ test (void) babl_component ("green"), babl_component ("blue"), NULL - )); + ) + ); babl_fish_process (fish, grayscale_buf, rgb_buf, -- 2.30.2